package org.jeecg.modules.cosmetic.controller;

import java.util.List;
import javax.annotation.Resource;

import org.jeecg.common.api.vo.Result;
import org.jeecg.modules.cosmetic.handler.ProductMaterialHandler;
import org.jeecg.modules.cosmetic.model.dto.ProductMaterialDTO;
import lombok.extern.slf4j.Slf4j;
import org.jeecg.modules.cosmetic.model.vo.ProductMaterialEditorVO;
import org.jeecg.modules.cosmetic.utils.MyValidateUtil;
import org.springframework.web.bind.annotation.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

/**
 * @Description: 产品关联资料
 * @Author: jeecg-boot
 * @Date: 2022-06-30
 * @Version: V1.0
 */
@Api(tags = "产品关联资料")
@RestController
@RequestMapping("/api/material")
@Slf4j
public class TProductMaterialController {
    @Resource
    private ProductMaterialHandler productMaterialHandler;

    @ApiOperation(value = "产品关联资料-列表查询", notes = "产品关联资料-列表查询")
    @GetMapping(value = "/list")
    public Result<List<ProductMaterialDTO>> queryList(@RequestParam(name = "productId", required = true) Long productId,
                                                      @RequestParam(name = "type", required = true) Integer type) {
        return productMaterialHandler.queryProductMaterialList(productId, type);
    }

    @ApiOperation(value = "产品关联资料-编辑资料", notes = "产品关联资料-编辑资料")
    @PostMapping(value = "/editor")
    public Result<?> editor(@RequestBody ProductMaterialEditorVO vo) {
        MyValidateUtil.validThrow(vo);
        return productMaterialHandler.editorMaterial(vo);
    }

    @ApiOperation(value = "产品关联资料-详情", notes = "产品关联资料-详情")
    @GetMapping(value = "/detail")
    public Result<ProductMaterialDTO> detail(@RequestParam(name = "id", required = true) Long id) {
        return productMaterialHandler.queryMaterialDetailByPrimary(id);
    }

    @ApiOperation(value = "产品关联资料-删除", notes = "产品关联资料-删除")
    @GetMapping(value = "/delete")
    public Result<?> delete(@RequestParam(name = "id", required = true) Long id) {
        return productMaterialHandler.deleteProductMaterial(id);
    }

}
